package com.kedacom.demo.quartz2;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TestService {

	@Resource
	private JdbcTemplate jdbcTemplate;

	public void executeSomeSql() {
		jdbcTemplate.queryForObject("select 1", Integer.class);
	}

	public void executeSomeBadSqlV1() {
		jdbcTemplate.execute("insert into qrtz_locks(lock_name) values('trigger_access')");
		jdbcTemplate.execute("insert into qrtz_locks(lock_name) values('trigger_access')");
	}

	public void executeSomeBadSqlV2() {
		jdbcTemplate.execute("insert into qrtz_locks(sched_name,lock_name) values('demo_scheduler','trigger_access')");
		jdbcTemplate.execute("insert into qrtz_locks(sched_name,lock_name) values('demo_scheduler','trigger_access')");
	}

	@Transactional(readOnly = true)
	public void executeSomeSqlWithReadOnlyTransactional() {
		jdbcTemplate.queryForObject("select 1", Integer.class);
	}

	public void doWithoutSql() {
		// do something
		System.out.println(1);
	}

}
